package com.zhuhjay.boot.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zhuhjay.constant.MessageConstant;
import com.zhuhjay.domain.entity.Setmeal;
import com.zhuhjay.domain.http.Result;
import com.zhuhjay.service.SetmealService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhuhjay
 * @since 2022-04-02
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    private SetmealService setmealService;

    @GetMapping("/all")
    public Result findAll(){
        try{
            List<Setmeal> list = setmealService.list();
            return new Result(true, MessageConstant.QUERY_SETMEALLIST_SUCCESS, list);
        }catch (Exception e){
            return new Result(false, MessageConstant.QUERY_SETMEALLIST_FAIL);
        }
    }

    @GetMapping("/{id}/{detail}")
    public Result findById(@PathVariable("id") Integer id, @PathVariable("detail") boolean detail){
        try{
            Setmeal setmeal;
            if( detail ){
                setmeal = setmealService.findAllTableInfoBySetmealId(id);
            }else{
                setmeal = setmealService.getById(id);
            }
            return new Result(true, MessageConstant.QUERY_SETMEAL_SUCCESS, setmeal);
        }catch (Exception e){
            return new Result(false, MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }

}
